/*
** term.c for 42sh in /home/guina_b/
** 
** Made by benoit guina
** Login   <guina_b@epitech.net>
** 
** Started on  Fri Jan 01 00:00:00 2010 benoit guina
** Last update Fri Jan 01 00:00:00 2010 benoit guina
*/

#include <unistd.h>
#include <errno.h>
#include "error.h"
#include "alloc.h"
#include "env.h"
#include "term.h"

t_term *term_get()
{
  static t_term term;

  return (&term);
}

t_term *term_init(t_env *env)
{
  t_term *r;

  r = term_get();
  env = env;
  return (r);
}

void term_free(t_term *term)
{
  xfree(term);
}

char *term_get_input(t_term *term)
{
  int i;

  if ((i = read(STDIN_FILENO, term->buf, sizeof(term->buf) - 1)) == -1)
    error_print(SH_ERR_READ, 0);
  if (i == 0 && !isatty(STDIN_FILENO))
    return (0);
  term->buf[i - (i > 0)] = 0;
  return (term->buf);
}
